package com.go8.goods.service;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.go8.common.MysqlPageWrapper;
import com.go8.goods.mapper.BrandMapper;
import com.go8.goods.pojo.Brand;

@Service
public class BrandServiceImpl implements BrandService {
	@Autowired
	private BrandMapper brandMapper;
	
	@Override
	public void add(Brand brand) {
		Date now = new Date();
		brand.setGmtModified(now);
		brand.setGmtCreate(now);
		brandMapper.insert(brand);
	}

	@Override
	public void updateById(Brand brand) {
		brand.setGmtModified(new Date());
		brandMapper.updateByPrimaryKeySelective(brand);
	}

	@Override
	public void deleteById(Long id) {
		brandMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Brand> getBrandsByCondition(MysqlPageWrapper<Brand> condition) {
		return brandMapper.selectByCondition(condition);
	}

	@Override
	public long getCountByCondition(Brand condition) {
		return brandMapper.selectCountByCondition(condition);
	}

	@Override
	public Brand getBrandById(long id) {
		return brandMapper.selectByPrimaryKey(id);
	}

	@Override
	public void deleteByIds(String ids) {
		String[] aid = ids.split(",");
		for(String sd : aid) {
			long id = Long.parseLong(sd);
			brandMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public List<Brand> getBrandsByCid(Long cid) {
		return brandMapper.selectByCatalogId(cid);
	}
}
